<template>
  <div>
    <el-dialog :title="title" :visible.sync="assignTasksVisible" :append-to-body="true" @close="close()"
               style="text-align: center">
      <div style="text-align: center">
        <el-form :inline="true" :model="dataForm" ref="dataForm" @keyup.enter.native="getDataList()" size="mini"
                 label-width="150px">
          <el-form-item label="申请姓名：">
            <el-input v-model="dataForm.search" placeholder="申请姓名" clearable></el-input>
          </el-form-item>
          <el-form-item label="申请手机号：">
            <el-input v-model="dataForm.mobliePhone" placeholder="申请手机号" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div style="text-align: center">
        <el-button @click="getDataList()" size="mini" type="primary">查询</el-button>
        <el-button @click="reset()" size="mini">重置</el-button>
      </div>
      <hr/>
      <div style="margin-bottom: 5px;margin-top: 5px;text-align: left">
        <el-button @click="_assignTask()" size="mini" type="primary">领取任务</el-button>
      </div>

      <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle"
                style="width: 100%;border-radius: 5px" size="mini" class="width-bg"
                border tooltip-effect="dark" :header-cell-style="{background:'#eef1f6',color:'#606266'}">
        <el-table-column type="selection" header-align="center" align="center" width="50">
        </el-table-column>
        <el-table-column prop="name" header-align="center" align="center" label="名称">
        </el-table-column>
        <el-table-column prop="mobliePhone" header-align="center" align="center" label="手机号">
        </el-table-column>
        <el-table-column prop="processId" header-align="center" align="center" label="流程实例号">
        </el-table-column>
        <el-table-column prop="taskId" header-align="center" align="center" label="任务号">
        </el-table-column>
        <el-table-column prop="createTime" header-align="center" align="center" label="开始时间">
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-dialog>
  </div>
</template>

<script>
    import {toAssignTasksPage,assignTask} from '@/api/flow';

    export default {
        data() {
            return {
                dataForm: {
                    search: '',
                    mobliePhone: ''
                },
                dataList: [],
                pageIndex: 1,
                pageSize: 10,
                totalPage: 0,
                dataListLoading: false,
                dataListSelections: [],
                addOrUpdateVisible: false,
                viewFlowVisible: true,
                flowDetails: null,
                taskDatailsVisible: false
            }
        },
        props:{
            assignTasksVisible:{default:()=>{ return false }}
        },
        components: {},
        activated() {
            this.getDataList()
        },
        methods: {
            // 获取数据列表
            getDataList() {
                this.dataListLoading = true
                const param = {
                    'current': this.pageIndex,
                    'size': this.pageSize,
                    'condition': this.dataForm
                }
                const requestData = {
                    'data': param
                }
                toAssignTasksPage(requestData).then((res) => {
                    this.dataListLoading = false
                    if (res.code == '0000') {
                        this.dataList = res.data.records
                        this.totalPage = res.data.total
                    } else {
                        this.dataList = []
                        this.totalPage = 0
                    }
                }).catch((err) => {

                })
            },
            // 每页数
            sizeChangeHandle(val) {
                this.pageSize = val
                this.pageIndex = 1
                this.getDataList()
            },
            // 当前页
            currentChangeHandle(val) {
                this.pageIndex = val
                this.getDataList()
            },
            // 多选
            selectionChangeHandle(val) {
                this.dataListSelections = val
            },
            reset() {
                this.dataForm.search = null
                this.dataForm.mobliePhone = null
                this.pageIndex = 1
                this.getDataList()
            },
            viewFlowColse() {
                this.viewFlowVisible = false;
            },
            closeTaskDetails() {
                this.taskDatailsVisible = false
            },
            close(){
                this.$emit('closeAssignTask')
            },
            _assignTask(){
                if(this.dataListSelections==null || this.dataListSelections.length!=1){
                    this.$message({message: '请选择一条数据！', duration: 800});
                    return;
                }
                const param= {
                    'processId': this.flowDetails.processId,
                    'taskId': this.flowDetails.taskId
                }
                const requestData={
                    'data':param
                }
                assignTask(requestData).then((res)=>{
                    if(res.code=='0000'){
                        this.$message({message: '获取任务成功！', duration: 800});
                        this.close();
                    }else{
                        this.$message({message: res.message, duration: 800});
                    }
                }).catch((err)=>{

                })
            }
        }
    }
</script>
